package com.zhiyou.app.shop.website.action;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.zhiyou.app.shop.common.BaseAction;
import com.zhiyou.app.shop.common.util.Page;
import com.zhiyou.app.shop.common.util.ShopConstants;
import com.zhiyou.app.shop.website.dao.pojo.DicItem;
import com.zhiyou.app.shop.website.dao.pojo.News;
import com.zhiyou.app.shop.website.dao.pojo.User;
import com.zhiyou.app.shop.website.dao.pojo.UserAccount;
import com.zhiyou.app.shop.website.service.IDicItemService;
import com.zhiyou.app.shop.website.service.ILoclistService;
import com.zhiyou.app.shop.website.service.INewsService;
import com.zhiyou.app.shop.website.service.IStockService;
import com.zhiyou.app.shop.website.service.IUserAccountService;

public class IndexAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	
	@Autowired
	private IUserAccountService userAccountService;
	@Autowired
	private IDicItemService dicItemService;
	@Autowired
	private INewsService newsService;
	@Autowired
	private IStockService stockService;

	private String month;
	private String day;
	private BigDecimal balance;
	private List<DicItem> levels; //用户级别的数据字典
	private List<News> news;
	private float prize;
	
	
	public String menu(){
		//获取当前日期
		try {
			Date date = new Date();
			DateFormat format = new SimpleDateFormat("MM");
			month = format.format(date);
			format = new SimpleDateFormat("dd");
			day = format.format(date);
			//获取该账号奖金余额
			User user = (User) getSession().get(ShopConstants.LOGIN_USER);
			UserAccount userAccount = userAccountService.findUserAccount(user.getUserAccount());
			if(userAccount != null){
				balance = userAccount.getBonusMoney();
			}else{
				balance = new BigDecimal(0.00);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String index(){
		levels = dicItemService.findByType(ShopConstants.LEVEL);
		pageSize = 8;
		newsService.getNews(getInitedPage());
		prize = stockService.findPrice();
		return SUCCESS;
	}

	public String getMonth() {
		return month;
	}

	public void setMonth(String month) {
		this.month = month;
	}

	public String getDay() {
		return day;
	}

	public void setDay(String day) {
		this.day = day;
	}

	public BigDecimal getBalance() {
		return balance;
	}

	public void setBalance(BigDecimal balance) {
		this.balance = balance;
	}

	public List<DicItem> getLevels() {
		return levels;
	}

	public void setLevels(List<DicItem> levels) {
		this.levels = levels;
	}

	public List<News> getNews() {
		return news;
	}

	public void setNews(List<News> news) {
		this.news = news;
	}

	public float getPrize() {
		return prize;
	}

	public void setPrize(float prize) {
		this.prize = prize;
	}
}
